// Learn TypeScript:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html

import CharacterManager from "../../Models/Characters/CharacterManager";
import FuBenManager from "../../Models/FuBens/FuBenManager";
import BaseUI from "../BaseUI";
import FuBenItem from "../UIItems/FuBenItem";

const { ccclass, property } = cc._decorator;

@ccclass
export default class FuBenUI extends BaseUI {
    @property(cc.Label)
    challengeTimesTxt: cc.Label = null;
    @property(cc.Prefab)
    funbenPrefab: cc.Prefab = null;
    @property(cc.ScrollView)
    scrollview: cc.ScrollView = null;

    enemyIds: number[] = [20001, 20002, 20003, 20004, 20005];
    protected onLoad(): void {
        for (let i = 0; i < this.enemyIds.length; i++) {
            var nodeItem = cc.instantiate(this.funbenPrefab);
            this.scrollview.content.addChild(nodeItem);
        }
    }


    protected onEnable(): void {

        FuBenManager.single.requestResetFuBenCount();
        this.drawView();
        this.challengeTimesTxt.string = "悬赏挑战次数：" + FuBenManager.single.getFuBenCount() + "/5";
    }

    protected onDisable(): void {

    }

    drawView() {
        var arr = this.scrollview.content.children;

        for (let i = 0; i < arr.length; i++) {
            var fubenItem = arr[i].getComponent(FuBenItem);
            var tp = CharacterManager.single.getCharacterTemplate(this.enemyIds[i]);
            fubenItem.drawItem(tp);
        }
    }

}
